package com.tiger.easyrpc.core.metadata;

import java.util.HashMap;
import java.util.Map;

public class MetadataManager {
    private Map<Object,Map<String,FetcherMetadata>> fetcherMetadataMap = new HashMap<>();
    private Map<String,ExporterMetadata> exporterMetadataMap = new HashMap<>();
    private static MetadataManager metadataManager = new MetadataManager();
    private MetadataManager(){}

    public static MetadataManager getInstance(){
        return metadataManager;
    }
    public FetcherMetadata getFetcherMetadata(Object source,String defineClass){
        if(fetcherMetadataMap.get(source) != null)
            return fetcherMetadataMap.get(source).get(defineClass);
        return null;
    }

    public void setFetcherMetadata(FetcherMetadata metadata){
        String defineClass = metadata.getDefineClass();
        Map<String,FetcherMetadata> arg1 = this.fetcherMetadataMap.get(metadata.getSource());
        if(arg1 !=null){
            arg1.putIfAbsent(defineClass,metadata);
            return;
        }
        arg1 = new HashMap<>();
        arg1.put(defineClass,metadata);
        this.fetcherMetadataMap.putIfAbsent(metadata.getSource(), arg1);
    }

    public void setExporterMetadata(String className,ExporterMetadata metadata){
        exporterMetadataMap.put(className,metadata);
    }

    public ExporterMetadata getExportMetadata(String className){
        return exporterMetadataMap.get(className);
    }
}
